home *** CD-ROM | disk | FTP | other *** search
- ;==========================================================================;
- ; Timer service for the 8530 ;
- ; ;
- ; Copyright 1986, 1987 by H. Roy Engehausen. All rights reserved. ;
- ; This software may be freely distributed and used, but it may not ;
- ; under any circumstances be sold by anyone other than the author. ;
- ; It may be distributed by a commercial company as long as it is ;
- ; for no cost. ;
- ; ;
- ; Permission is explicity granted to use this code as a model for ;
- ; other programs requiring interrupt driven serial I/O as long as they ;
- ; carry this copyright notice and the imbedded constants ;
- ; ;
- ; Inputs: SI = COM block ;
- ;==========================================================================;
-
- ;--------------------------------------------------------------------------;
- ; Transmitter on? If so go check it ;
- ;--------------------------------------------------------------------------;
-
- TEST flags[SI],flags_xmt_on ; Transmitter on?
- JNZ tmr_8530_tx_on
-
- ;--------------------------------------------------------------------------;
- ; If full duplex, ignore the DCD check ;
- ;--------------------------------------------------------------------------;
-
- TEST options[SI],opt_fd ; Full duplex?
- JNZ tmr_8530_fd_on
-
- ;--------------------------------------------------------------------------;
- ; Zero the slot timer? If so, do it and then we are done ;
- ;--------------------------------------------------------------------------;
-
- TEST flags[SI],flags_dcd_on ; DCD on?
- JZ tmr_8530_no_dcd ; Nope
-
- MOV timer_dcd[SI],0 ; Zero the timer since DCD is on
-
- JMP tmr_8530_done ; All done
-
- ;--------------------------------------------------------------------------;
- ; Slot timer running. Increment as needed and check for slot to be done ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_no_dcd:
-
- MOV AX,timer_dcd[SI] ; Get timer
-
- CMP AL,value_slot[SI] ; Slot expired?
- JAE tmr_8530_slot_over ; Yes...
- JMP tmr_8530_no_slot ; Nope
-
- ;--------------------------------------------------------------------------;
- ; Slot complete. See if P lets us thru? ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_slot_over: ;
-
- CALL random ; Get a random number
- CMP AL,value_p[SI] ; Check against "P" (the probability)
- JBE tmr_8530_fd_on ; Send it!
-
- MOV timer_dcd[SI],0 ; Zero the timer to get to next slot
- JMP tmr_8530_done ; All done
-
- ;--------------------------------------------------------------------------;
- ; We have either satisfied P/slot or this is a full duplex ;
- ; link. See if any output pending so we can send it. ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_fd_on: ;
-
- CMP buffer_t_a[SI],0 ; Is there a transmit buffer?
- JNZ tmr_8530_start_t ; Yes.. We need to start the xmtr
- JMP tmr_8530_done ; No... All done
-
- ;--------------------------------------------------------------------------;
- ; Turn on transmitter ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_start_t: ;
-
- MOV DX,baseaddr[SI] ; Get port address
- CALL ton_clk_8530 ; Call the routine
-
- JMP tmr_8530_done ; All done
-
- ;--------------------------------------------------------------------------;
- ; Increment DCD counter and exit ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_no_slot:
-
- INC AX
- MOV timer_dcd[SI],AX ; Bump timer
- JMP tmr_8530_done ; All done
-
- ;--------------------------------------------------------------------------;
- ; Transmitter is on. See what timing period we are in and take action ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_tx_on:
-
- MOV AX,timer_xmtr[SI] ; Get xmtr time value
- INC AX ; Bump up
-
- SUB BH,BH ; Clear top of register
- MOV BL,period_xmtr[SI] ; Get time period
-
- JMP CS:tmr_8530_table[BX] ; Go do routine
-
- tmr_8530_table LABEL WORD ;
- DW OFFSET tmr_8530_txd ; 0 = Waiting for TXD
- DW OFFSET tmr_8530_done ; 2 = Transmitter running, ignore
- DW OFFSET tmr_8530_crc ; 4 = Waiting for CRC to finish
-
- ;--------------------------------------------------------------------------;
- ; Waiting for TXD to terminate ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_txd: ;
-
- CMP AX,value_txd[SI] ; TXD done?
- JBE tmr_8530_xmtr_done ; No.. Don't do anything
-
- ;--------------------------------------------------------------------------;
- ; TXD complete .. start sending a packet ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_start_packet:
-
- MOV buffer_t_out[SI],0 ; Set buffer pointer to 0 since we are
- ; about to send first character
- ; and this points to character sent!
-
- MOV period_xmtr[SI],period_x_tx ; Event = sending data
-
- MOV DX,baseaddr[SI] ; Get chip address
-
- CALL int_8530 ; Change interrupt mask as needed
-
- MOV AL,rst_tcrc ; Reset XMTR CRC
- OUT DX,AL ;
-
- MOV ES,buffer_t_a[SI] ; Get buffer address
- MOV AL,ES:0 ; Get first character
-
- OR DL,scc_data_mask ; Get the data port address
- OUT DX,AL ; Send the character
- AND DL,0FFH-scc_data_mask ; Convert back to control address
-
- MOV AL,rst_eom ; Reset Underrun, End of Frame Flag
- OUT DX,AL ;
-
- SUB AX,AX ; Set transmitter timer to zero
-
- JMP tmr_8530_xmtr_done ; All done
-
- ;--------------------------------------------------------------------------;
- ; Packet complete. This waits for the CRC to be sent. The 8530 has no ;
- ; way of telling us when the packet is finished being sent so we wait ;
- ; some amount of time before continuing. This is based on the speed. ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_crc: ;
-
- CMP AX,value_crc[SI] ; TXD done?
- JBE tmr_8530_xmtr_done ; No.. Don't do anything
-
- ; See if more packets are pending. If so, we don't need TXD so just start
- ; sending. The buffer just sent has already been dequeued in the
- ; interrupt handler
-
- CMP buffer_t_a[SI],0 ; Any buffers there?
- JZ tmr_8530_crc_nomore ; Nope.. Finish up
- JMP tmr_8530_start_packet ; Yep.. Send the packet
-
- tmr_8530_crc_nomore: ;
-
- ; CRC complete -- turn transmitter off!
-
- MOV DX,baseaddr[SI] ; Get chip address
- MOV AL,sccreg5 ; WR5
- OUT DX,AL ;
- MOV AL,dtr_pin+tx_8bits+tx_crcen ; DTR+8bits+crc
- OUT DX,AL ;
-
- AND flags[SI],0FFH-flags_xmt_on-flags_tbe ; Transmitter now off
-
- TEST options[SI],opt_fd ; Full duplex?
- JNZ tmr_8530_crc_fd ; Yes.. No clock changes
-
- CALL ron_clk_8530 ; Enable receiver and clock
- JMP tmr_8530_done ; All done
-
- tmr_8530_crc_fd:
-
- CALL ron_8530 ; Enable receiver but not clock
- JMP tmr_8530_done ; All done
-
- ;--------------------------------------------------------------------------;
- ; Transmitter timer functions done. Set the transmitter timer ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_xmtr_done: ;
-
- MOV timer_xmtr[SI],AX ; Set transmitter value
-
- ;--------------------------------------------------------------------------;
- ; All timer functions for 8530 are done ;
- ;--------------------------------------------------------------------------;
-
- tmr_8530_done: